package com.speedata.utils;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;


/**
 * @author xuyan
 */
public class HnweUtils {

    private static BufferedWriter TorchFileWrite;


    /**
     * 分别控制灯光
     *
     * @param str 指令
     */
    public static void goodsLight(String str) {
        String pathName = "/sys/class/misc/aw9523/gpio";

        if (str.startsWith("0") || str.startsWith("1")) {
            pathName = "/sys/class/misc/aw9523/gpio";
        } else if (str.startsWith("2") || str.startsWith("3")) {
            pathName = "/sys/class/misc/aw9524/gpio";
        } else if (str.startsWith("4") || str.startsWith("5")) {
            pathName = "/sys/class/misc/aw9525/gpio";
        } else if (str.startsWith("6") || str.startsWith("7")) {
            pathName = "/sys/class/misc/aw9526/gpio";
        }

        Logcat.d("-print-rece-" + "goodsLight " + str + " start");
        File mTorchFileName = new File(pathName);
        try {
            TorchFileWrite = new BufferedWriter(new FileWriter(mTorchFileName, false));
            TorchFileWrite.write(str);
            TorchFileWrite.flush();
            TorchFileWrite.close();
        } catch (IOException e) {
            e.printStackTrace();
            Logcat.d(e.getMessage());
        }
        Logcat.d("-print-rece-" + "goodsLight " + str + " end");
    }


    /**
     * 补光灯
     * @param str
     */
    public static void openCloseFlash(String str) {

        File TorchFileName = new File("/sys/class/misc/lm3642/torch");
        try {
            TorchFileWrite = new BufferedWriter(new FileWriter(TorchFileName, false));
            TorchFileWrite.write(str);
            TorchFileWrite.flush();
            TorchFileWrite.close();
        } catch (IOException e) {
            e.printStackTrace();

        }

    }

}
